package consultan.vanke.com.view

import android.content.Context
import android.view.MotionEvent
import androidx.core.widget.NestedScrollView
import kotlin.math.abs

/**
 * Created by Andy on 2020/9/30
 */
class MyNestedScrollView(context: Context) : NestedScrollView(context) {

    private var mDownPosX: Float = 0.0f
    private var mDownPosY: Float = 0.0f

    override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
        val x = ev.x
        val y = ev.y
        when (ev.action) {
            MotionEvent.ACTION_DOWN -> {
                mDownPosX = x
                mDownPosY = y
            }
            MotionEvent.ACTION_MOVE -> {
                val deltaX: Float = abs(x - mDownPosX)
                val deltaY: Float = abs(y - mDownPosY)
                if (deltaX > deltaY) {
                    return false
                }
            }
        }
        return super.onInterceptTouchEvent(ev)
    }
}